let uu = document.querySelector('#recommen>ul')
let el = ''
fetch("http://chst.vip:1234/api/getmoneyctrl")
    .then(body => body.json())
    .then(res => {
        console.log(res)
        res.result.forEach(item => {
            let regExp = /(?<=imgurl=)[^'"]*/;
            // console.log(item)
            //处理图片
            let r = item.productImgSm.match(regExp);
            // console.log(r)
            el += `<li class="clearfix" productid=${item.productId}>
            <img src=${r} alt="">
            <div class="info">
                <div class="title">
                    <h4>${item.productName}<span>${item.productPinkage}</span>
                    </h4>
                </div>
                <div class="other">
                    <b>${item.productFrom}|${item.productTime}</b><em>${item.productComCount}</em>
                </div>
            </div>
        </li>`
        })
        uu.innerHTML = el;
    })
// let container = document.querySelector('nav>.container>.more')
// let flag = false
// container.onclick = function () {

//     if (!flag) {
//         $(this).parent().next().slideUp(200)
//     } else {
//         flag = true
//         $(this).parent().next().sliseDown(200)
//     }

// }
// uu.onclick = function (e) {
//     if (e.target.localName == 'li') {
//         let _this = e.target
//         console.log(_this)
//         let id = _this.getAttribute('productid')
//         // location.href = './indexXiang.html?productid=' + id
//         location.href = './indexXiang.html'
//     }
// }

// let lis=document.querySelectorAll('#recommen>li')
// for(var i=0;i<lis.length;i++){
//     lis[i].onclick=function(e){
//         let id=this.getAttribute('productid')
//         location.href='indexXiang.html'
//     }
// }
uu.onclick = e => {
    let _this = e.target;
    if (_this.localName === "li") {
        let id = _this.getAttribute('productid')
        console.log(id);
        location.href = "./indexXiang.html?productid=" + id
    } else if (_this.localName === "div" || _this.localName === "img") {
        let id = _this.parentNode.getAttribute('productid')
        console.log(id);
        location.href = "./indexXiang.html?productid=" + id
    } else if (_this.localName === "h4" || _this.localName === "b") {
        let id = _this.parentNode.parentNode.parentNode.getAttribute('productid')
        location.href = "./indexXiang.html?productid=" + id
        console.log(id);

    }
}
